package top.zackyoung.druid.simple.service;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.zackyoung.druid.simple.MyDataSource;
import top.zackyoung.druid.simple.config.DynamicDataSourceSwitcher;
import top.zackyoung.druid.simple.mapper.UserMapper;

import javax.annotation.Resource;

/**
 * @author ZackYoung
 * @version 1.0
 * @date 2021/9/28
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserService {
     final UserMapper userMapper;

    public Object getUsers() {
        return userMapper.selectAllUser();
    }

    @MyDataSource(DynamicDataSourceSwitcher.SLAVE1)
    public Object getUserById(Long userId) {
        return userMapper.selectByPrimaryKey(userId);
    }
}
